<?php
/*
	代理商管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?:'list';
$tabs=array(
	array('op'=>'list','title'=>'代理商列表'),
	
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$total='';
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('agent_member',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['area_code']=pdo_getcolumn('core_area',array('code'=>$item['area_code']),'address');
			$item['url']=$this->get_agent_login_url($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','edit'=>false,'key'=>'mid','delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'代理商信息','type'=>'member'),
			array('name'=>'type','title'=>'代理商类型','type'=>'radio','options'=>'types'),
			array('name'=>'createtime','title'=>'成为代理商时间','type'=>'time'),
			array('name'=>'stop','title'=>'代理商状态','type'=>'radio','options'=>'stops'),
		),'action'=>array(
			array('type'=>'post','op'=>'stop','title'=>'禁止','show'=>array('stop'=>0)),
			array('type'=>'post','op'=>'start','title'=>'启用','show'=>array('stop'=>1)),
			array('type'=>'href','op'=>'list','action'=>'agent.agent_area','title'=>'代理地区'),
			array('type'=>'href','op'=>'add','action'=>'agent.add','title'=>'添加代理地区'),
			array('type'=>'modal','op'=>'cpassword','action'=>'member.member','plugin'=>'core','title'=>'重置密码'),
			array('type'=>'open','name'=>'url','title'=>'进入代理后台'),
		)),
		
	);
	$return['htmls']=$htmls;
	$return['types']=$this->agent_types();
	$return['stops']=array(
		'0'=>'正常',
		'1'=>'禁用',
	);
	exi($return);
}

if($_RQ['op']=='stop'){
	$mid=intval($_RQ['mid']);
	if(!$mid){
		exi('请先选择要设置的代理商！','error');
	}
	$this->update('agent_member',array('stop'=>1),array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
	exi('禁止成功！','','list');
}
if($_RQ['op']=='start'){
	$mid=intval($_RQ['mid']);
	if(!$mid){
		exi('请先选择要设置的代理商！','error');
	}
	$this->update('agent_member',array('stop'=>0),array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
	exi('启用成功！','','list');
}
if($_RQ['op']=='detail'){
	//显示代理商详细信息
	
}
if($_RQ['op']=='del'){
	//删除代理商
	$mid=intval($_RQ['mid']);
	if(!$mid){
		exi('请先选择代理商！','error');
	}
	$this->delete('agent_member',array('mid'=>$mid));
	exi('删除成功！','','list');
}